package com.sreManager.controller.web;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.sreManager.Constant;
import com.sreManager.domain.LoginUsers;
import com.sreManager.mapper.LogsMapper;
import com.sreManager.web.util.CommonUtil;
import com.sreManager.web.util.LoginManager;

@Controller
@RequestMapping(value={"/log/"})
public class LogController extends CommonController{
	@Autowired LogsMapper logsMapper;
	String TILESForder = "log";
	@ModelAttribute("menuType")
	public String type(){
		return TILESForder;
	}
	/**
	 * 리스트
	 * @return
	 */
	@RequestMapping(value={"list"})
	public String list(Model model, @RequestParam HashMap<String, Object> paramMap){
		// 로그인 유저 정보
		LoginUsers loginUser = LoginManager.getInstance().getSession(request);

		if(!loginUser.getRole().equals(Constant.ADMIN)){
			return "redirect:/unuse";
		}

		Integer pageDataTotal = logsMapper.selectLogPagingCount(paramMap);
		model.addAttribute("pageDataTotal", pageDataTotal);
    	if(pageDataTotal!=null && pageDataTotal > 0){
    		paramMap = CommonUtil.pagingNumCheck(paramMap, pageDataTotal);
    		model.addAttribute("pagingList", logsMapper.selectLogPagingList(paramMap));
    	}
		model.addAttribute("pageParam", paramMap);

		paramMap = new HashMap<String, Object>();
		paramMap.put("group", Constant.MENU_USED);
		model.addAttribute("menuUsedList", codeMapper.selectCodeList(paramMap));
		paramMap.put("group", Constant.LOGS_TYPE);
		model.addAttribute("logTypeList", codeMapper.selectCodeList(paramMap));
		return TILESForder+"/list"+Constant.TILES;
	}

}
